<?php

namespace App\Sdks\Feishu\Traits;

trait Text
{
    /**
     * @param $open_id
     * @param $content
     * @return mixed
     * 发送文本至open_id
     */
    public function sendTextToOpenId($open_id, $content){
        return $this->sendText('open_id', $open_id, $content);
    }

    /**
     * @param $chat_id
     * @param $content
     * @return mixed
     * 发送文本至chat_id
     */
    public function sendTextToChatId($chat_id, $content){
        return $this->sendText('chat_id', $chat_id, $content);
    }

    /**
     * @param $target
     * @param $targetId
     * @param $content
     * @return mixed
     * 发送文本
     */
    public function sendText($target, $targetId, $content){
        $url = $this->getApiUrl('message_send');

        $param = [
            $target => $targetId,
            "msg_type" => 'text',
            "content" => [
                'text' => $content,
            ],
        ];

        $ret = $this->authRequest($url, $param, 'POST');

        return $ret;
    }
}
